package com.jinzw.jform.rows

import android.content.Context
import android.util.Patterns
import android.view.inputmethod.EditorInfo

open class PhoneRow(context: Context) : TextRow(context) {

    init {
        validator = { v -> v != null && v.length <=11 }
        addOnViewCreatedListener<PhoneRow> {
            editView?.inputType = EditorInfo.TYPE_CLASS_PHONE
        }

        addValueChangeListener<PhoneRow> { r, s ->
            if (validator(s)){
            }else{
                r?.editView?.setText(s?.substring(0,11))
                r?.editView?.setSelection(11)
            }

        }
    }

    override fun rulewen(): Pair<Boolean, String> {
        var mvalue=this.value()
        if (mvalue?.length!=11){
            return Pair(true,"请输入正确的手机号")
        }
        return super.rulewen()
    }
}